import Vue from 'vue'
import Router from 'vue-router'
//解决重复点菜单报红问题
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}


Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/Product',
    component: () => import('@/views/Product/index'),
    hidden: true
  },
  {
    path: '/FAQ',
    component: () => import('@/views/FAQ/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/manageboard',
    children: [
      {
        path: 'manageboard',
        component: () => import('@/views/manageboard/index'),
        name: 'index',
        meta: { title: '支付驾驶舱', icon: 'dashboard', affix: true }

      },
      {
        path: 'databoard',
        component: () => import('@/views/databoard/index'),
        name: 'dataroom',
        meta: { title: '业务看板', icon: 'dashboard', affix: true }

      }, {
        path: 'client',
        component: () => import('@/views/clientboard/index'),
        name: 'clientroom',
        meta: { title: '首页', icon: 'dashboard', affix: true }

      }, {
        path: 'sumboard',
        component: () => import('@/views/sumboard/index'),
        name: 'sumroom',
        meta: { title: '支付看板', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/Cpn',
    name: '支付管理',
    meta: { title: '支付管理', icon: '' },
    component: Layout,
    children: [
      {
        path: '/Cpn/CpnActCfgInfo',
        name: 'CpnActCfgInfo',
        component: () => import('@/views/Cpn/CpnActCfgInfo'),
        meta: { title: '支付配置', icon: '', keepAlive: true }

      },
      {
        path: '/Cpn/CpnPyMchinRct',
        name: 'CpnPyMchinRct',
        component: () => import('@/views/Cpn/CpnPyMchinRct'),
        meta: { title: '支付前置机配置', icon: '', keepAlive: true }

      },
      {
        path: '/Cpn/CpnPyMchinRctPos',
        name: 'CpnPyMchinRctPos',
        component: () => import('@/views/Cpn/CpnPyMchinRctPos'),
        meta: { title: 'PosServer前置机配置', icon: '', keepAlive: true }
      },
      {
        path: '/Cpn/CpnIndex',
        name: 'CpnIndex',
        component: () => import('@/views/Cpn/CpnIndex'),
        meta: { title: '企业管理', icon: '', keepAlive: true }
      },
      {
        path: '/Cpn/CpnOrg',
        name: 'CpnOrg',
        component: () => import('@/views/Cpn/CpnOrg'),
        meta: { title: '门店管理', icon: '', keepAlive: true }

      },
      {
        path: '/CpnActCfgBll/CpnActCfgBll',
        name: 'CpnActCfgBll',
        component: () => import('@/views/CpnActCfgBll/CpnActCfgBll'),
        meta: { title: '支付审核', icon: '', keepAlive: true }

      }
    ]
  },
  {
    path: '/Reconciliation/Rcncbtch',
    name: '企业对账',
    meta: { title: '企业对账', icon: '' },
    component: Layout,
    children: [
      {
        path: '/Reconciliation/Rcncbtch',
        name: 'Rcncbtch',
        component: () => import('@/views/Reconciliation/Rcncbtch'),
        meta: { title: '企业对账单', icon: '', keepAlive: true }

      },
      {
        path: '/Reconciliation/Channel',
        name: 'Channel',
        component: () => import('@/views/Reconciliation/Channel'),
        meta: { title: '渠道对账单', icon: '', keepAlive: true }

      },
      {
        path: '/Reconciliation/DifOrds',
        name: 'DifOrds',
        component: () => import('@/views/Reconciliation/DifOrds'),
        meta: { title: '差异数据', icon: '', keepAlive: true }

      },
      {
        path: '/Reconciliation/RcnHandRcd',
        name: 'RcnHandRcd',
        component: () => import('@/views/Reconciliation/RcnHandRcd'),
        meta: { title: '异常处理记录', icon: '', keepAlive: true }

      },
      {
        path: '/Reconciliation/ReconciliationToExcel',
        name: 'ReconciliationToExcel',
        component: () => import('@/views/Reconciliation/ReconciliationToExcel'),
        meta: { title: '三方对账单', icon: '', keepAlive: true }

      },,
      {
        path: '/Reconciliation/ReconciliationToExcelERP',
        name: 'ReconciliationToExcel',
        component: () => import('@/views/Reconciliation/ReconciliationToExcelERP'),
        meta: { title: 'ERP对账单下载', icon: '', keepAlive: true }

      }
    ]
  },
  {
    path: '/Cpn/ActChannelCfgInfo',
    name: '运营事件',
    meta: { title: '活动管理', icon: '' },
    component: Layout,
    children:
      [
        {
          path: '/Cpn/ActChannelCfgInfo',
          name: 'ActChannelCfgInfo',
          component: () => import('@/views/Cpn/ActChannelCfgInfo'),
          meta: { title: '企业分账', icon: '', keepAlive: true }

        },
        {
          path: '/Cpn/SttlmntRc',
          name: 'SttlmntRc',
          component: () => import('@/views/Cpn/SttlmntRc'),
          meta: { title: '结算分账', icon: '', keepAlive: true }

        },
        {
          path: '/Cpn/ActChannelCfgGood',
          name: 'ActChannelCfgGood',
          component: () => import('@/views/Cpn/ActChannelCfgGood'),
          meta: { title: '单品营销', icon: '', keepAlive: true }

        },
        {
          path: '/CpnActCfgBll/ActChannelcfgBll',
          name: 'ActChannelcfgBll',
          component: () => import('@/views/CpnActCfgBll/ActChannelcfgBll'),
          meta: { title: '分账审核', icon: '', keepAlive: true }

        },
        {
          path: '/CpnActCfgBll/GoodActChannelcfgBll',
          name: 'GoodActChannelcfgBll',
          component: () => import('@/views/CpnActCfgBll/GoodActChannelcfgBll'),
          meta: { title: '单品审核', icon: '', keepAlive: true }

        }
      ]
  },

  {
    path: '/Report/Itemized',
    name: '订单管理',
    meta: { title: '订单管理', icon: '' },
    component: Layout,
    children:
      [
        {
          path: '/Report/Itemized',
          name: 'Itemized',
          component: () => import('@/views/Report/Itemized'),
          meta: { title: '前置机订单', icon: '', keepAlive: true }

        },
        {
          path: '/Report/OthPay',
          name: 'OthPay',
          component: () => import('@/views/Report/OthPay'),
          meta: { title: '第三方平台订单管理', icon: '', keepAlive: true }

        },
        {
          path: '/Report/ERP',
          name: 'ERP',
          component: () => import('@/views/Report/ERP'),
          meta: { title: '西联ERP订单管理', icon: '', keepAlive: true }

        },
        {
          path: '/Report/RealOrder',
          name: 'RealOrder',
          component: () => import('@/views/Report/RealOrder'),
          meta: { title: '实时订单查询', icon: '', keepAlive: true }

        }
      ]
  },
  {
    path: '/System',
    name: '系统设置',
    meta: { title: '系统设置', icon: '' },
    component: Layout,
    children: [
      {
        path: '/System/Module',
        name: 'Module',
        component: () => import('@/views/System/Module'),
        meta: { title: '模块管理', icon: '', keepAlive: true }

      },
      {
        path: '/System/Role',
        name: 'Role',
        component: () => import('@/views/System/Role'),
        meta: { title: '角色权限管理', icon: '', keepAlive: true }

      },
      {
        path: '/System/Manager',
        name: 'Manager',
        component: () => import('@/views/System/Manager'),
        meta: { title: '企业用户管理', icon: '', keepAlive: true }

      },
      {
        path: '/System/PyMcVerRcd',
        name: 'PyMcVerRcd',
        component: () => import('@/views/System/PyMcVerRcd'),
        meta: { title: '前置机版本', icon: '', keepAlive: true }

      },
      {
        path: '/System/AdminLog',
        name: 'AdminLog',
        component: () => import('@/views/System/AdminLog'),
        meta: { title: '操作日志管理', icon: '', keepAlive: true }

      },
      {
        path: '/PayChannel/PayChannel',
        name: 'PayChannel',
        component: () => import('@/views/PayChannel/PayChannel'),
        meta: { title: '通道配置管理', icon: '', keepAlive: true }

      },
      {
        path: '/System/Heartbeat',
        name: 'Heartbeat',
        component: () => import('@/views/System/Heartbeat'),
        meta: { title: '前置机监测', icon: '', keepAlive: true }

      },
      {
        path: '/ProductDoc/ProductDocTyp',
        name: 'ProductDocTyp',
        component: () => import('@/views/ProductDoc/ProductDocTyp'),
        meta: { title: '产品文档管理', icon: '', keepAlive: true }
      }
      ,
      {
        path: '/System/CpnNotcRcd',
        name: 'CpnNotcRcd',
        component: () => import('@/views/System/CpnNotcRcd'),
        meta: { title: '通知待办', icon: '', keepAlive: true }
      },
      {
        path: '/System/AlipayDev',
        name: 'AlipayDev',
        component: () => import('@/views/System/AlipayDev'),
        meta: { title: '设备管理', icon: '', keepAlive: true }
      }
    ]
  },
  { path: '*', redirect: '/404' }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes

})

const router = createRouter()

// Detail    see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
